package com.example.smart_video.utils;


import android.text.TextUtils;
import android.util.Log;


import com.alibaba.fastjson.JSON;
//import com.alibaba.sdk.android.oss.OSS;
//import com.alibaba.sdk.android.oss.OSSClient;
//import com.alibaba.sdk.android.oss.common.auth.OSSCustomSignerCredentialProvider;
//import com.alibaba.sdk.android.oss.common.utils.OSSUtils;
import com.example.cleandemo3.R;
import com.example.smart_video.model.Constants;
import com.wink_172.library.utils.MD5Tools;
import com.wink_172.library.utils.MMKVTool;

import org.xutils.common.Callback;
import org.xutils.common.util.MD5;
import org.xutils.http.RequestParams;
import org.xutils.x;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.SortedMap;
import java.util.TreeMap;


public class CommonUtils {
    private static final String TAG = "TAG";
    public static String readTxt(String path){
        String str = "";
        try {
            File urlFile = new File(path);
            InputStreamReader isr = new InputStreamReader(new FileInputStream(urlFile), "UTF-8");
            BufferedReader br = new BufferedReader(isr);

            String mimeTypeLine = null ;
            while ((mimeTypeLine = br.readLine()) != null) {
                str = str+mimeTypeLine;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return  str;
    }

/**
 * 隐藏文件是为了不在图库中显示
 * */
    public static String getTargetUrl(String url) {
        return Constants.saveSDPath + "." + url.substring(1, url.length());

    }

    public static void setLastPlayPos(int pos) {
        MMKVTool.setInt(x.app(), Constants.LAST_PLAY_POS, pos);
    }

    public static int getLastPlayPos() {
        return MMKVTool.getInt(x.app(), Constants.LAST_PLAY_POS, 1);
    }





    public static SortedMap getBaseSortedMap() {
        SortedMap<String, Object> parameters = new TreeMap<String, Object>();
        return parameters;
    }

    public static RequestParams getTargetRequest(String key, SortedMap<String, Object> parameters) {
        RequestParams params = new RequestParams(key);

        StringBuffer sbkey = new StringBuffer();
        Set es = parameters.entrySet();  //所有参与传参的参数按照accsii排序（升序）
        Iterator it = es.iterator();
        while (it.hasNext()) {
            Map.Entry entry = (Map.Entry) it.next();
            String k = (String) entry.getKey();

            String v = "";
            if (entry.getValue() instanceof String) {
                v = (String) entry.getValue();
            }
            //空值不传递，不参与签名组串
            if (null != v && !"".equals(v)) {
                params.addBodyParameter(k, v);
                sbkey.append(k + "=" + v + "&");//注意最后一个按道理是不需要加&
            }
        }


        return params;
    }







}
